package assignment01;

import java.io.Serializable;
import java.util.Comparator;


public class Bigram<F,S> implements Serializable {
	  F first;
	  S second;

	  public static class LexicographicBigramComparator<F,S>  implements Comparator<Bigram<F,S>> {
	    Comparator<F> firstComparator;
	    Comparator<S> secondComparator;

	    public int compare(Bigram<F, S> bigram1, Bigram<F, S> bigram2) {
	      int firstCompare = firstComparator.compare(bigram1.getFirst(), bigram2.getFirst());
	      if (firstCompare != 0)
	        return firstCompare;
	      return secondComparator.compare(bigram1.getSecond(), bigram2.getSecond());
	    }

	    public LexicographicBigramComparator(Comparator<F> firstComparator, Comparator<S> secondComparator) {
	      this.firstComparator = firstComparator;
	      this.secondComparator = secondComparator;
	    }
	  }


	  public F getFirst() {
	    return first;
	  }

	  public S getSecond() {
	    return second;
	  }

	  public void setFirst(F pFirst) {
	    first = pFirst;
	  }

	  public void setSecond(S pSecond) {
	    second = pSecond;
	  }


	  public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Bigram)) return false;

	    final Bigram bigram = (Bigram) o;

	    if (first != null ? !first.equals(bigram.first) : bigram.first != null) return false;
	    if (second != null ? !second.equals(bigram.second) : bigram.second != null) return false;

	    return true;
	  }

	  public int hashCode() {
	    int result;
	    result = (first != null ? first.hashCode() : 0);
	    result = 29 * result + (second != null ? second.hashCode() : 0);
	    return result;
	  }

	  public String toString() {
	    return "(" + getFirst() + ", " + getSecond() + ")";
	  }

	  public Bigram(F first, S second) {
	    this.first = first;
	    this.second = second;
	  }
	  
	 public Bigram() {
		 this.first = null;
		 this.second = null;
	 }
}
